#!/usr/bin/python3
# coding:utf-8

import rospy
import os
import numpy as np
from std_msgs.msg import Int32
import time
import shutil
from virus_scan import VirusScan
class Host_B:
    def __init__(self):
        rospy.init_node('Host_B', anonymous=True)
        self.rate = rospy.Rate(10)
        self.u_path = rospy.get_param("/host_b/u_path")
        
        self.virus_scan = VirusScan()

        self.global_status = 0

        rospy.Subscriber("/global_status", Int32, self.cb_global_status)
        self.status_publish = rospy.Publisher("/host_b_status", Int32, queue_size=1)

    def cb_global_status(self,data):
        self.global_status = data.data


    def MainLoop(self):
        while not rospy.is_shutdown():
            if self.global_status == 2:
                self.global_status = 0
                self.virus_scan.scan(self.u_path)
                self.status_publish.publish(1)
                
            self.rate.sleep()


if __name__ == '__main__':
    node1 = Host_B()
    node1.MainLoop()

